import numpy as np
import pandas as pd

# 探究星期数据以及涨跌幅是好是坏数据

# 1.读取数据
stock = pd.read_csv("../../resources/p00_data_mining/stock_day.csv")

# 2.准备数据
# 星期数据：pandas日期类型
date = pd.to_datetime(stock.index)
stock["week"] = date.weekday
# 涨跌幅数据
stock["pona"] = np.where(stock["p_change"] > 0, 1, 0)

# 3.交叉表
data = pd.crosstab(stock["week"], stock["pona"])
# 3.1 做除法后画图
data.div(data.sum(axis=1), axis=0).plot(kind="bar", stacked=True)

# 4.透视表操作
stock.pivot_table(["pona"], index=["week"])